package com.campus_information_portal.dao;

import com.campus_information_portal.entity.PartyMember;
//import com.campus_information_portal.util.PartyMemberProvider;
import com.campus_information_portal.entity.PartyMemberTemp;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import com.campus_information_portal.entity.PartyMemberPartyStudent;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 20155883 万珊
 * @description 党支部成员Dao接口
 * @project_name PartyMemberDao
 * @package com.campus_information_portal.dao
 * @create 2018-05-03 14:51
 **/
public interface PartyMemberDao {
    /**
     * @param partyMemberPartyStudent
     * @Description 查询党支部成员信息(分支部、身份、年级)
     * @author 20155883 万珊
     * @methodName queryPartyMemberByConditions
     * @returnType List
     * @create 2018/4/26 8:45
     **/
    @SelectProvider(type = PartyMemberSqlProvider.class, method = "queryPartyMemberByConditions")
    List<PartyMemberPartyStudent> queryPartyMemberByConditions(PartyMemberPartyStudent partyMemberPartyStudent);





    /**
     * @param party_member_account
     * @Description 删除党员
     * @author 20155883 万珊
     * @methodName deletePartyMember
     * @returnType boolean
     * @create 2018/4/26 8:45
     **/
    @Delete("delete from party_member where party_member_account=#{party_member_account}")
    boolean deletePartyMember(@Param("party_member_account") int party_member_account);

    /**
     * @param party_member_account
     * @Description 修改学生表中政治身份类型为0（即除去其政治身份）
     * @author 20155883 万珊
     * @methodName updateStudentPoliWithO
     * @returnType boolean
     * @create 2018/4/26 8:45
     **/
    @Update("update student set stu_poli=0 where stu_num=#{party_member_account}")
    boolean updateStudentPoliWithO(@Param("party_member_account") int party_member_account);

    /**
     * @param party_organization_num
     * @Description 党支部成员统计，通过党支部编号
     * @author 20155883 万珊
     * @methodName countMember
     * @returnType int
     * @create 2018/4/26 8:45
     **/
    @Select("select count(*) from party_member where party_organization_num=#{party_organization_num}")
    int countMember(@Param("party_organization_num")int party_organization_num);

    /**
     * @param party_member_account
     * @Description 根据党支部账户（教师编号/学生编号）查询所在党组织编号
     * @author 20155883 万珊
     * @methodName findPONBypartyMemberAccount
     * @returnType int
     * @create 2018/4/26 8:45
     **/
    @Select("select party_organization_num from party_member where party_member_account=#{party_member_account}")
    int findPONBypartyMemberAccount(@Param("party_member_account")int party_member_account);

    /**
     * @param party_member_account
     * @Description 根据党支部账户（教师编号/学生编号）查询所在党员信息
     * @author 20155883 万珊
     * @methodName queryPartyMemberByPMA
     * @returnType PartyMember
     * @create 2018/4/26 8:45
     **/
    @Select("select * from party_member where party_member_account=#{party_member_account}")
    PartyMember queryPartyMemberByPMA(@Param("party_member_account")int party_member_account);

    /**
     * @param partyMemberTemp
     * @Description 修改身份类型（保存），临时表
     * @author 20155883 万珊
     * @methodName savePartyMemberTemp
     * @returnType boolean
     * @create 2018/4/26 8:45
     **/
    @Insert("insert into party_member_temp(party_member_account,type_now,type_last) " +
            " values(#{partyMemberTemp.partyMemberAccount},#{partyMemberTemp.typeNow},#{partyMemberTemp.typeLast})")
    boolean savePartyMemberTemp(@Param("partyMemberTemp")PartyMemberTemp partyMemberTemp,@Param("id") int id);

    /**
     * @param partyMemberTemp
     * @Description 修改身份类型（保存），党员表
     * @author 20155883 万珊
     * @methodName savePartyMember
     * @returnType boolean
     * @create 2018/4/26 8:45
     **/
    @Update("update party_member set party_member_type=#{partyMemberTemp.typeNow},state=1 where party_member_account=#{partyMemberTemp.partyMemberAccount}")
    boolean savePartyMember(@Param("partyMemberTemp")PartyMemberTemp partyMemberTemp);

    /**
     * @param partyMember
     * @Description 修改身份类型（提交）,党员表
     * @author 20155883 万珊
     * @methodName commitPartyMember
     * @returnType boolean
     * @create 2018/4/26 8:45
     **/
    @Update("update party_member set party_member_type=#{partyMember.partyMemberType},state=0 where party_member_account=#{partyMember.partyMemberAccount}")
    boolean commitPartyMember(@Param("partyMember") PartyMember partyMember);

    /**
     * @param partyMember
     * @Description 修改身份类型（提交）,临时表
     * @author 20155883 万珊
     * @methodName commitPartyMemberTemp
     * @returnType boolean
     * @create 2018/4/26 8:45
     **/
    @Delete("delete from party_member_temp where party_member_account=#{partyMember.partyMemberAccount}")
    boolean commitPartyMemberTemp(@Param("partyMember") PartyMember partyMember);

    /**
     * @param partyMember
     * @Description 修改学生表中政治身份类型,（提交）
     * @author 20155883 万珊
     * @methodName updateStudentPoli
     * @returnType boolean
     * @create 2018/4/26 8:45
     **/
    @Update("update student set stu_poli=#{partyMember.partyMemberType} where stu_num=#{partyMember.partyMemberAccount}")
    boolean updateStudentPoli(@Param("partyMember") PartyMember partyMember);



    /**
     * @param party_member_account
     * @Description 查询该学生政治类型
     * @author 20155883 万珊
     * @methodName queryStudentPoli
     * @returnType int
     * @create 2018/4/26 8:45
     **/
    @Select("select stu_poli from student where stu_num=#{party_member_account}")
    int queryStudentPoli(@Param("party_member_account")int party_member_account);


    /**
     * @param partyMemberTemp
     * @Description 查找临时表是否有该党员保存记录
     * @author 20155883 万珊
     * @methodName queryPartyMemberTemp
     * @returnType PartyMemberTemp
     * @create 2018/4/26 8:45
     **/
    @Select("select * from party_member_temp where party_member_account=#{partyMemberTemp.partyMemberAccount}")
    PartyMemberTemp queryPartyMemberTemp(@Param("partyMemberTemp")PartyMemberTemp partyMemberTemp);

    /**
     * @param partyMemberTemp
     * @Description 覆盖临时表数据
     * @author 20155883 万珊
     * @methodName coverPartyMember
     * @returnType boolean
     * @create 2018/4/26 8:45
     **/
    @Update("update party_member_temp set type_now=#{partyMemberTemp.typeNow} where party_member_account=#{partyMemberTemp.partyMemberAccount}")
    boolean coverPartyMemberTemp(@Param("partyMemberTemp")PartyMemberTemp partyMemberTemp);


//    /**
//     * @param party_member_account
//     * @Description 设置党员表state为1，即临时表里有该党员保存数据
//     * @author 20155883 万珊
//     * @methodName updatePartyMemberStateWith1
//     * @returnType boolean
//     * @create 2018/4/26 8:45
//     **/
//    @Update("update party_member set state=1 where party_member_account=#{party_member_account}")
//    boolean updatePartyMemberStateWith1(@Param("party_member_account") int party_member_account);
//
//    /**
//     * @param party_member_account
//     * @Description 设置党员表state为0，即临时表里无该党员保存数据
//     * @author 20155883 万珊
//     * @methodName updatePartyMemberStateWith0
//     * @returnType boolean
//     * @create 2018/4/26 8:45
//     **/
//    @Update("update party_member set state=0 where party_member_account=#{party_member_account}")
//    boolean updatePartyMemberStateWith0(@Param("party_member_account") int party_member_account);
//
//    /**
//     * @param party_member_account
//     * @Description 查找党员临时表里该人的政治身份
//     * @author 20155883 万珊
//     * @methodName queryPMTypeOnTemp
//     * @returnType boolean
//     * @create 2018/4/26 8:45
//     **/
//    @Select("select party_member_type from party_member_temp where party_member_account=#{party_member_account}")
//    int queryPMTypeOnTemp(@Param("party_member_account")int party_member_account);
}
